package com.biglead.demo.rabbit.order.delay;


import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OrderDelayedMQSender {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendOrderDelayMessage(String msg, Integer delayTime) {
        log.info("发送订单自动取消的消息 {} : {}", delayTime, msg);
        //将消息携带路由键值
        rabbitTemplate.convertAndSend(
                OrderDelayedMessageConfig.DELAYED_EXCHANGE,
                OrderDelayedMessageConfig.ROUTING_KEY,
                msg,
                message -> {
                    message.getMessageProperties().setDelay(delayTime);
                    return message;
                });
    }

}
